export async function sendAudioToWs(audioBlob) {
  return new Promise((resolve, reject) => {
    const ws = new WebSocket('ws://localhost:8000/ws/asr_emotion')
    ws.binaryType = 'arraybuffer'
    ws.onopen = () => {
      audioBlob.arrayBuffer().then(buffer => {
        ws.send(buffer)
      })
    }
    ws.onmessage = (event) => {
      try {
        const data = JSON.parse(event.data)
        resolve(data)
      } catch (e) {
        reject(e)
      } finally {
        ws.close()
      }
    }
    ws.onerror = (err) => {
      reject(err)
    }
  })
}